﻿using BussinessObject.ObjectTwo;
using Class_Entity.ObjectTwo;
using DataAccess.ObjectTwo;
using ProjectHK3.App_Code;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectHK3.Object_One
{
    public partial class CreateBranch : System.Web.UI.Page
    {
        D_LoadDrop dl = new D_LoadDrop();
        CC_Branches br = new CC_Branches();
        B_Insert bi = new B_Insert();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                load();
            }
        }
        public void load()
        {
            DropDownList1.DataSource = dl.Company();
            DropDownList1.DataTextField = "COMPANY_NAME";
            DropDownList1.DataValueField = "COMPANY_ID";
            DropDownList1.DataBind();

            DropDownList2.DataSource = dl.City();
            DropDownList2.DataTextField = "CITY_NAME";
            DropDownList2.DataValueField = "CITY_ID";
            DropDownList2.DataBind();
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            br.BRANCH_CODE = TextBox1.Text;
            br.BRANCH_NAME = TextBox2.Text;
            br.ADDRESS = TextBox3.Text;
            br.BRANCH_PHONE = TextBox4.Text;
            br.DESCRIPTION = TextBox5.Text;
            br.COMPANY_ID =int.Parse( DropDownList1.SelectedValue.ToString());
            br.CITY_ID = int.Parse(DropDownList2.SelectedValue.ToString());
            if (bi.InsertBranch(br) == true)
            {
                Alert.Show("Insert Sucessful!!!");
            }
            else
            {
                Alert.Show("Insert Fail. Please try again!!!");
            }
        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            TextBox1.Text = "";
            TextBox2.Text = "";
            TextBox3.Text = "";
            TextBox4.Text = "";
            TextBox5.Text = "";
            TextBox1.Focus();
            DropDownList1.SelectedIndex = 0;
            DropDownList2.SelectedIndex = 0;
        }
    }
}